<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    输入: ["flower","flow","flight"]
        输出: "fl"-->
</head>
<body>
    <script>
        /**
         * @param {string[]} strs
         * @return {string}
         */
        var longestCommonPrefix = function(strs) {
            let final='',flag=true
            if (!strs.length){
                return final
            }
            for (let i = 0; i < strs[0].length; i++) {
                let reg = new RegExp('^'+strs[0].slice(0,i+1))
                strs.forEach(res =>{
                    if (!res.match(reg)){
                        flag=false
                    }
                })
                if (flag){
                    final = strs[0].slice(0,i+1)
                }else{
                    return final
                }
            }
            return final
        };
        var strs = ["dog","dogracecar","dogcar"]
        console.log(longestCommonPrefix(strs));
    </script>

</body>
</html>
